#!/bin/bash
mkdir -p bms-base/src/main/java
echo "build ..."
rm -rf output/*
mkdir -p output

if [ "ci" = $1 ] ; then
    mvn clean compile -pl bms-base,bms-bundle -am -Dbdgc.skip=false
elif [ "ut" = $1 ] ; then
    mvn clean verify -pl bms-jacoco-report -am -Put -Dbdgc.skip=false
elif [ "package_admin" = $1 ] ; then
    cd bms-admin
    npm install
    npm run build:prod
    tar -czf dist.tar.gz ./dist
    cp dist.tar.gz ../output
    cd ..
elif [ "docker_admin" = $1 ] ; then
    cd bms-admin
    npm install
    npm run build:prod
    cp -r dist ../output
    cp Dockerfile nginx.conf ../output
    cd ../output
    docker build . -t fastjrun/bms-admin:3.0.0
    cd ..
elif [ "package_server" = $1 ] ; then
    mvn clean package -pl bms-server -am -Dbdgc.skip=false
    cp bms-server/target/bms-server.jar ./output
elif [ "docker_server" = $1 ] ; then
    mvn clean package -pl bms-server -am -Dbdgc.skip=false
    cp bms-server/target/bms-server.jar ./output
    cp bms-server/Dockerfile ./output
    cd output
    docker build . -t fastjrun/bms-server:3.0
    cd ..
elif [ "package_mock_server" = $1 ] ; then
    mvn clean package -pl bms-mock-server -am -Dbdmgc.skip=false
    cp bms-mock-server/target/bms-mock-server.jar ./output
elif [ "clean_all" = $1 ] ; then
    mvn clean
    rm -rf output
    rm -rf bms-bundle/src
    rm -rf bms-bundle-mock/src
fi
echo "build done."
